<?php
/**
 * Created by PhpStorm.
 * User: teddy
 * Date: 16-1-4
 * Time: 下午7:13
 */


session_start();

/*get user name & password*/
$username = $_POST['username'];
$password = $_POST['password'];

$con = mysqli_connect("192.168.2.191","root","pwd","APITEST");

if (!$con) {
    die('Could not connect: ' . mysql_error());
}
else {
    /*query user*/
    $selectSQL = "SELECT pwd FROM APITEST.Users where Name = '" . $username . "'";
    $outputArray[] = null;
    mysqli_query($con, "set character set 'utf8'");
    $result = mysqli_query($con,$selectSQL);
    $rows = mysqli_fetch_row($result);
    /*if pwd is right*/
    if($rows != null) {
        if($rows[0] == $password)
        {
            /*correct, set session*/
            $_SESSION["usr"] = $username;
            /*link to CaseManage page*/
            header("Location:Manage.php");
        }
        else
        {
            header("Location:Error.html");
        }
    }
    else
    {
        header("Location:Error.html");
    }
}